// <editor-fold defaultstate="collapsed" desc="抖音打印">
//-----油站名称-----
//券名称：xx
//核销时间：xx
//商品名称：xx
//商品数量：xx
//积分数量：xx
//核销时间：xx

class PrintCouponBean {

  PrintCouponBean({
    this.couponName,
    this.goodsQuantity,
    this.mchGoodsName,
    this.consumeIntegral,
    this.payAmount,
    String? receiveTime,
    String? couponOilName,
  })  : receiveTime = receiveTime ?? _getTimeNowString(),
        couponOilName = couponOilName ?? _getLoginMerchantName();
  final String? couponName; //券名称
  final String? goodsQuantity; //商品数量
  final String? mchGoodsName; //商品名称
  final String? consumeIntegral; //商品积分
  final String? payAmount; //商品金额
  final String receiveTime;
  final String couponOilName;

  static String _getTimeNowString() {
    // 实现获取当前时间的逻辑
    return DateTime.now().toString();
  }

  static String _getLoginMerchantName() {
    // 实现获取登录商户名称的逻辑
    return "";
  }
}
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="打印基类">
/// 打印基类
abstract class BasePrintBean { //对⻬⽅式：0=居左 1=居中 2=居右

  BasePrintBean({required this.alignment});
  final int alignment;

  //字体
  static const double TEXT_SIZE_BIG = 30.0;
  static const double TEXT_SIZE_MID = 24.0;
  static const double TEXT_SIZE_FORM_SIZE = 20.0; //自定义小票表格使用
  static const double TEXT_SIZE_SMALL = 18.0;

  //居中
  static const int LEFT = 0;
  static const int CENTER = 1;
  static const int RIGHT = 2;

  @override
  String toString() {
    return super.toString();
  }
}

/// 空行打印
class BlankLinePrintBean extends BasePrintBean { //空行数

  BlankLinePrintBean({
    required int alignment,
    required this.blankLineCount,
  }) : super(alignment: alignment);
  int blankLineCount;

  @override
  String toString() => "[TAGPrintTAG] ---> ";
}

/// 划线打印
class DashLinePrintBean extends BasePrintBean {
  DashLinePrintBean({
    int alignment = 1,
  }) : super(alignment: alignment);

  @override
  String toString() => "[TAGPrintTAG] ---> --------------";
}

/// 图形打印
class ImagePrintBean extends BasePrintBean { //0=同printBitmap 1=阈值200的⿊⽩化图⽚ 2=灰度图⽚

  ImagePrintBean({
    required int alignment,
    required this.bitmap,
    required this.type,
  }) : super(alignment: alignment);
  /// 图⽚像素分辨率⼩于2M，且宽度根据纸张规格设置（58为384像素，80为576像素）
  /// 如果超过纸张宽度将不显示
  final dynamic bitmap; // 在Flutter中使用Image或者Uint8List
  final int type;

  @override
  String toString() => "[TAGPrintTAG] ---> bitmap=[$bitmap]";
}

/// 文本打印
class TextPrintBean extends BasePrintBean { //下划线

  TextPrintBean({
    required super.alignment,
    required this.text,
    required this.textSize,
    required this.isBold,
    this.isUnderLine = false,
  });
  final String text; //文本
  final double textSize; //字体大小
  final bool isBold; //加粗
  bool isUnderLine;

  @override
  String toString() => '[TAGPrintTAG] ---> [$text] \t [$alignment] \t [$textSize] \t [$isBold]';
}

/// 表格列文本打印
class ColumnsTextPrintBean extends BasePrintBean {

  ColumnsTextPrintBean({
    required this.colsTextArr,
    required this.receiptStyle,
    this.textSize = BasePrintBean.TEXT_SIZE_FORM_SIZE,
  }) : super(alignment: 1);
  //各列⽂本字符串数组
  final List<String> colsTextArr;

  //字体大小
  final double textSize;

  //小票样式
  final String receiptStyle;

  @override
  String toString() => "[TAGPrintTAG] ---> $colsTextArr \t [$textSize]";

  //各列宽度权重(即各列所占⽐)
  List<int> getColsWidthWeightArr() => getIntArrayData(colsTextArr.length, receiptStyle);

  //各列对⻬⽅式：0=居左 1=居中 2=居右
  List<int> getColsAlign() => _getIntArrayColsAlign(colsTextArr.length);

  //是否加粗
  bool isBold = false;

  //是否下划线
  bool isUnderLine = false;

  // static List<int> getIntArrayData(int arraySize, String receiptStyle) {
  //   switch (arraySize) {
  //     case 1:
  //       return [1];
  //     case 2:
  //       return [3, 1];
  //     case 3:
  //       if (receiptStyle.contains('STORE_ORDER')) {
  //         return [8, 4, 3];
  //       } else {
  //         return [1, 1, 1]; //16 4 3
  //       }
  //     case 4:
  //       return [2, 2, 2, 2];
  //     case 5:
  //       return [6, 4, 4, 4, 4];
  //     default:
  //       return [6, 4, 4, 4, 4, 4];
  //   }
  // }

  // 2列：（21，10）
  // 3列：（17，5，8）
  // 4列：（13，5，5，6）
  // 5列：（10，4，4，5，5）
  // 6列：（8，4，4，3，4，4）
  static List<int> getIntArrayData(int arraySize, String receiptStyle) {
    switch (arraySize) {
      case 2:
        return [21, 10];
      case 3:
        if (receiptStyle.contains('STORE_ORDER')) {
          return [17, 5, 8];
        } else {
          return [11, 10, 10]; //16 4 3
        }
      case 4:
        return [13, 5, 5, 6];
      case 5:
        return [10, 4, 4, 5, 5];
      default:
        return [8, 4, 4, 3, 4, 4];
    }
  }

  static List<int> _getIntArrayColsAlign(int arraySize) {
    switch (arraySize) {
      case 1:
        return [0];
      case 2:
        return [0, 2];
      case 3:
        return [0, 1, 2];
      case 4:
        return [0, 1, 1, 2];
      case 5:
        return [0, 1, 1, 1, 2];
      default:
        return [0, 1, 1, 1, 1, 2];
    }
  }
}

/// 条码打印
class CodePrintBean extends BasePrintBean {

  CodePrintBean({
    required this.codeData,
    required this.codeType,
  }) : super(alignment: 1);

  final String codeData;  //码的内容
  final int codeType;     //码的类型：0=一维码  1=二维码

  @override
  String toString() => '[TAGPrintTAG] ---> codeData=[$codeData] codeType=$codeType';
}
// </editor-fold>
